Guided Practice 6.5: Descendant Trees

Question 1: Design a function person-double-name that takes a Person and returns a Person just like the given one, except that the Person and all of his descendants have their names doubled. For example,

(person-double-name
  (make-person "chuck" 
               (list (make-person "alice" empty) 
                     (make-person "bob" empty))))
=
(make-person "chuckchuck" 
             (list (make-person "alicealice" empty) 
                   (make-person "bobbob" empty)))

Try doing it by straightforward structural decomposition, and then try it again using HOFs for the portion of the data that is represented as a list. Remember that you will only learn something if you actually do it yourself.

[Solution to Question 1]

Question 2: Design the following function:
;; person-descendant? : Person String -> Boolean
;; GIVEN: a person and a name
;; RETURNS: true iff that person or any of his/her descendants has
;; that name.
;; EXAMPLES:
;; Given the persons in the lesson:
(begin-for-test
  (check-true (person-descendant? fred "bob"))
  (check-true (person-descendant? chuck "bob"))
  (check-false (person-descendant? chuck "eddie"))
  (check-false (person-descendant? fred "eve")))

Try doing it by straightforward structural decomposition, and then try it again using HOFs.

[Solution to Question 2]


Last modified: Mon Sep 26 14:07:32 Eastern Daylight Time 2016